<?php
/**
 * 用户表模型
 * @author      HJC <hujianchuang@haowj.com>
 * @update      2014.06.28
 * @since       Version 1.0
 * 
 */
class User_course_staticModel extends Model
{
    //获取用户最近上的一次课
    public function getNowCourse($user_id,$classType='')
    {
        if($user_id=='') return false;
        if($classType) $sql = " and type=".$classType;
        $count = $this->where("user_id=".$user_id.$sql)->count('id');
        if($count==0) return false;
        if($count==1) return $courseType =  $this->where("user_id=".$user_id.$sql)->order("id asc")->getField('c_type');
        $courseType = $this->where("user_id=".$user_id." and total_hours>haveon+stayon ".$sql)->order("id asc")->getField('c_type');
        if(empty($courseType)) return $courseType = $this->where("user_id=".$user_id.$sql)->order("id asc")->getField('c_type');
        else return $courseType;
    }
    //获取有效期
    public  function getTimes($user_id,$courseType='')
    {
        if($courseType) $sql = " and c_type=".$courseType;
        $result = $this->where("user_id=".$user_id.$sql)->order("id asc")->field('effect_time,expiration_time')->find();
        return $result;
    }
}